#include "Fou.h"
#include "iostream"

Fou::Fou()
{
}

Fou::Fou(int x,int y, bool white)
{
    m_x = x;
    m_y = y;
    m_white = white;

}
char
Fou::tostring()
{
    return( isWhite() ? 'F' : 'f');
}

void
Fou::affiche()
{
    cout << "Pion: x=" << m_x << " y=" << m_y << " "
         << ( isWhite() ? "blanche" : "noire" ) << endl;

}

bool
Fou::mouvementvalide(Echiquier *e, int x, int y )
{

    if (Piece::mouvementvalide(e,x,y))
    {
        bool valide = true;
        int i = 1;

        if(x > m_x && y > m_y && m_y-y == m_x-x)
        {
            if(x-m_x>1)
            {
                while(i < x - m_x && valide)
                {
                    if(e->getPiece(x-i,y-i) == 0)
                        i++;
                    else
                        valide = false;
                }
                return valide;
            }
            else
               return true;
        }

        else if(x < m_x && y < m_y && y-m_y == x-m_x)
        {
            if(m_x-x>1)
            {
                while(i < m_x-x && valide)
                {
                    if(e->getPiece(x+i,y+i) == 0)
                        i++;
                    else
                        valide = false;

                }

                return valide;
            }
            else
                return true;
        }
        else if(x > m_x && y < m_y && m_y-y == x-m_x)
        {
            if(x-m_x>1)
            {
                while(i < x - m_x && valide)
                {
                    if(e->getPiece(x-i,y+i) == 0)
                        i++;
                    else
                        valide = false;
                }
                return valide;
            }
            else
                return true;
        }
        else if(x < m_x && y > m_y && y-m_y == m_x-x)
        {
            if(m_x-x>1)
            {
                while(i < m_x-x && valide)
                {
                    if(e->getPiece(x+i,y-i) == 0)
                        i++;
                    else
                        valide = false;
                }
                return valide;
            }
            else
                return true;
        }
        else
            return false;

    }
    else
        return false;
}

Fou::~Fou(){}
